//
//  SISDKSendRequest.m
//  test1
//
//  Created by Piccolo on 2017/4/10.
//  Copyright © 2017年 Piccolo. All rights reserved.
//

#import "SISDKSendRequest.h"

static CBPeripheral *peripheral;
static CBCharacteristic *write_characteristic;
static NSData *calendar_data;
static NSData* characteristic_value_buffer;
static NSMutableArray *valueArray;
static BOOL is_first_verify = YES;


@implementation SISDKSendRequest




//set periperal & characteristic
+ (void)setPeripheralAndCharacteristic:(CBPeripheral *)per andCharacteristic:(CBCharacteristic *)writeCha{
    peripheral = per;
    write_characteristic = writeCha;
}

+ (void)writeValueWithMessageType:(SmartITBluetoothSendType)sendRequestWithSmartITBluetoothSendType andOption:(NSDictionary *)option{
    NSData *dateData = [SmartITSendSourceRequest sendRequestWithSmartITBluetoothSendType:sendRequestWithSmartITBluetoothSendType withOption:option];
//    NSLog(@"@31请求已发送");
    [peripheral writeValue:dateData forCharacteristic:write_characteristic type:CBCharacteristicWriteWithoutResponse];
}

+ (void)disconnectBle{
    [[SICPSDKBlueToothTool sharedManager] disconnectBle];
    is_first_verify = YES;
}

+ (void)setFirstVerify:(BOOL)boolean{
    is_first_verify = boolean;
}
+ (BOOL)isFirstVerify{
    return is_first_verify;
}

+ (NSArray *)getRequest{
    valueArray = [[[SICPSDKBlueToothTool sharedManager] getValueOfCharacteristic] copy] ;
    return valueArray;
}

+ (void)setActiveReportingValueOfCharacteristic:(NSData *)activeReportingValue{
    if ([activeReportingValue length] > 0){
//        NSLog(@"@83:%@", activeReportingValue);
        Byte *ddd = (Byte *)activeReportingValue.bytes;
        
        if (ddd[0] == 0x10 || ddd[0] == 0x11){
            [SICPSDKService manageActiveReportingValueOfCharacteristic:activeReportingValue];
        }
    }
}


+ (void)startDetectActiveReportingValueOfCharacteristic{
    [[SICPSDKBlueToothTool sharedManager] startDetectActiveReportingValueOfCharacteristic];
}

+ (NSInteger)getMaxCountFromCommandWorder:(unsigned char)word{
    if ((word >= 0x40 && word <= 0x45) || (word >= 0x48 && word <= 0x4d)) {
        return 3;
    }else if (word == 0x46 || word == 0x47 || word == 0x4e || word == 0x4f){
        return 2;
    }else{
        return 1;
    }
}

+ (void)sendSettingDeviceTime {
    //SmartITBluetoothSendTypeSetDeviceTimeInfo
    NSData *sendData = [SmartITSendSourceRequest sendRequestWithSmartITBluetoothSendType:SmartITBluetoothSendTypeSetDeviceTimeInfo withOption:nil];
    NSLog(@"@82:%@", sendData);
    [peripheral writeValue:sendData forCharacteristic:write_characteristic type:CBCharacteristicWriteWithoutResponse];
}

+ (void)sendSettingInfoWithLight:(SmartITCampingLightInfo *)smartITCampingLightInfo {
    NSDictionary *option = [NSDictionary dictionaryWithObjectsAndKeys:smartITCampingLightInfo, @"smart_it_camping_light_info", nil];
    NSData *sendData = [SmartITSendSourceRequest sendRequestWithSmartITBluetoothSendType:SmartITBluetoothSendTypeSendSettingInfo withOption:option];
    NSLog(@"@89:%@", sendData);
    [peripheral writeValue:sendData forCharacteristic:write_characteristic type:CBCharacteristicWriteWithoutResponse];
}

+ (void)sendSosNeedBlink:(BOOL)needBlink {
    NSDictionary *option = [NSDictionary dictionaryWithObjectsAndKeys:@(needBlink), @"blink", nil];
    NSData *sendData = [SmartITSendSourceRequest sendRequestWithSmartITBluetoothSendType:SmartITBluetoothSendTypeSetSOS withOption:option];
    NSLog(@"@88:%@", sendData);
    [peripheral writeValue:sendData forCharacteristic:write_characteristic type:CBCharacteristicWriteWithoutResponse];
}

+ (void)sendSoundControl:(BOOL)needSoundControl {
    NSDictionary *option = [NSDictionary dictionaryWithObjectsAndKeys:@(needSoundControl), @"sound_control", nil];
    NSData *sendData = [SmartITSendSourceRequest sendRequestWithSmartITBluetoothSendType:SmartITBluetoothSendTypeSetSoundControl withOption:option];
    NSLog(@"@96:%@", sendData);
    [peripheral writeValue:sendData forCharacteristic:write_characteristic type:CBCharacteristicWriteWithoutResponse];
}

+ (void)sendGetDeviceStatus {
    NSData *sendData = [SmartITSendSourceRequest sendRequestWithSmartITBluetoothSendType:SmartITBluetoothSendTypeGetDeviceStatus withOption:nil];
    [peripheral writeValue:sendData forCharacteristic:write_characteristic type:CBCharacteristicWriteWithoutResponse];
}


@end

